Param(
  [Parameter(Mandatory=$true)] [string]$Root,  # 包含若干 <视频名>/ 图片文件夹的根目录
  [string]$OutDir = './upload_zips',          # 输出 zip 的目录
  [switch]$Use7Zip,                           # 使用 7-Zip 分卷
  [int]$VolumeMB = 1024                       # 分卷大小（MB），仅 $Use7Zip 时生效
)

New-Item -ItemType Directory -Force -Path $OutDir | Out-Null

$folders = Get-ChildItem -Directory -Path $Root
if ($folders.Count -eq 0) { Write-Warning "未发现子文件夹：$Root"; exit 0 }

foreach ($d in $folders) {
  $name = $d.Name
  $zipPath = Join-Path $OutDir ("$name.zip")
  if ($Use7Zip) {
    $seven = "C:\\Program Files\\7-Zip\\7z.exe"
    if (-not (Test-Path $seven)) { Write-Error "未找到 7-Zip：$seven"; exit 1 }
    Write-Host "7-Zip 分卷压缩 → $name" -ForegroundColor Green
    & $seven a -tzip -mx=5 ("$zipPath") (Join-Path $d.FullName '*') ("-v$($VolumeMB)m") | Out-Null
  } else {
    Write-Host "压缩 → $name" -ForegroundColor Green
    if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
    Compress-Archive -Path (Join-Path $d.FullName '*') -DestinationPath $zipPath -Force
  }
}

Write-Host "完成。请上传 $OutDir 下的 zip 到 UGREENLink：Yolo训练集/03_frames_raw" -ForegroundColor Cyan

